<?php
/*=============================================================================
|| ##################################################################
||	phpFoX Konsort
|| ##################################################################
||
||	Copyright		: (C) 2005-2007 PHPFOX Limited a Reality Fox Creation
||	Contact			: info@phpfox.com
||
||	- phpFoX and all of its source code and files are protected by Copyright Laws.
||
||	- The license for phpFoX permits you to install this software on a single domain (.com, .org, .net, etc.).
||
||	- You may also not remove this copyright screen which shows the copyright information and credits for phpFoX (RealityFOX Creations).
||
||	- phpFoX Konsort is NOT a FREE software - http://www.phpfox.com/license/
||
|| ##################################################################
=============================================================================*/

/* $File: ./include/modules/Account/classes/PhpFox_ComponentFeaturedMember.class.php, $Author:  $ */

/** Display random featured member.
 *
 * @package module.account
 * @version $Id: PhpFox_ComponentFeaturedMember.class.php 46 2007-12-14 23:12:21Z phpfoxsv $
 *
 */
class PhpFox_Mod_Account_ComponentFeaturedMember extends BaseComponent
{

    /** Processing method
     */
	function process()
	{
		$oCache = &App::getCache();
		$oCache->setFile('featured_members.php');

		if ( !$oCache->isCached() )
		{
			$aItems = $this->oDatabase->getRows("SELECT id, user, gender, day, month, year, city, location, state FROM ". App::getT('user') ." WHERE verify = '0' AND feature = '1'");
			$oCache->save($aItems);
		}

		$aMembers = $oCache->doRequire();

		if ( count($aMembers) > 0 )
		{
			$iTotalDisplay = App::getParam('user_feature_count');

			$i = 0;
			$aFeatMembers = array();
			shuffle($aMembers);
			foreach($aMembers as $aMember)
			{
				$i++;
				if ( $i > $iTotalDisplay )
				{
					break;
				}

				$iAge = date('Y') - $aMember['year'];
		    	$iCurrDate = date('m') * 100 + date('d');
		    	$iBirthDate = $aMember['month'] * 100 + $aMember['day'];
		    	if ($iCurrDate < $iBirthDate)
		    	{
		    	    $iAge--;
		    	}
				$aMember['age'] = (isset($iAge) ? $iAge : '');
			    $aMember['gender'] = $aMember['gender'];
				$aFeatMembers[] = $aMember;
			}
		}
		else
		{
			return '';
		}

		$oTpl = &$this->_oModule->getTemplate();
		$oTpl->assign(array(
			'aFeatMembers' => (isset($aFeatMembers) ? $aFeatMembers : ''),
		));

		$srcHtml = $oTpl->fetch('FeaturedMember.html');
		return $srcHtml;
	}
}
?>